/** @type {import('next').NextConfig} */
const path = require('path')

const nextConfig = {
  sassOptions: {
    includePaths: [path.join(__dirname, 'styles')],
    prependData: `@import "@/styles/mixin.scss";`,
  },
  images: {
    domains: ['avatars.githubusercontent.com'], // 添加github头像服务的域名
  },
  experimental: {
    webpackBuildWorker: true
  },
  webpack(config) {
    const fileLoaderRule = config.module.rules.find((rule) =>
      rule.test?.test?.('.svg'),
    );
    config.module.rules.push(
      {
        ...fileLoaderRule,
        test: /\.svg$/i,
        resourceQuery: /url/, // *.svg?url
      },
      {
        test: /\.svg$/i,
        issuer: fileLoaderRule.issuer,
        resourceQuery: { not: [...fileLoaderRule.resourceQuery.not, /url/] }, // exclude if *.svg?url
        use: ['@svgr/webpack'],
      }
    ); // 针对 SVG 的处理规则
    fileLoaderRule.exclude = /\.svg$/i
    return config;
  }
}

module.exports = nextConfig
